package com.demo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.util.ResourceUtils;


public class GeneratorSqlmap {
    /**
     * mybatis 自动生成方法
     *
     * @throws Exception 抛出异常
     */
    public void generator() throws Exception {
        List<String> warnings = new ArrayList<>();
        File configFile = ResourceUtils.getFile("classpath:config/generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                callback, warnings);
        myBatisGenerator.generate(null);
    }
 
    /**
     * main 启动方法
     *
     * @param args main args
     */
    public static void main(String[] args) {
        try {
            new GeneratorSqlmap().generator();
            System.out.println("SUCCESS");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("ERROR");
        }
    }
}
